package com.ipartek.formacion.ficheros;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class PruebaFichero {

	static final String PATH_FILE1 = "data/datos.txt";
	static final String PATH_DATA = "data/";

	static FileReader fr;
	static FileWriter frChar;
	static FileInputStream inputStream;
	static FileOutputStream frInt;

	public static void main(String[] args) throws IOException {

		try {
			fr = new FileReader(PATH_FILE1);
			frChar = new FileWriter(PATH_DATA + "datos2.txt");

			int c;
			while ((c = fr.read()) != -1) {
				// System.out.print((char) c);
				if (c == 64) {
					frChar.write("[El valor 64]");
				}

				frChar.write(c);

			}
			inputStream = new FileInputStream(PATH_FILE1);
			frInt = new FileOutputStream(PATH_DATA + "datosInt.txt");

			c = 0;
			while ((c = inputStream.read()) != -1) {
				frInt.write(c);
			}

		} catch (FileNotFoundException e) {
			System.out.println("FileNotFoundException ");
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("IOException ");
			System.out.println("No encuentra el fichero " + PATH_FILE1);
			e.printStackTrace();
		} catch (Exception e) {
			System.out.println("Exception general");
			e.printStackTrace();
		} finally {
			fr.close();
			frChar.close();
			frInt.close();
		}

	}

}
